package com.ztesoft.web.taskscheduling;

import java.util.List;

import com.ztesoft.core.spring.context.SpringApplicationContextHolder;
import com.ztesoft.framework.log.ZTEsoftLogManager;
import com.ztesoft.web.taskgenerator.db.dao.DmTaskStageDao;
import com.ztesoft.web.taskgenerator.db.po.DmTaskPO;
import com.ztesoft.web.taskgenerator.db.po.DmTaskStagePO;
import com.ztesoft.web.taskscheduling.service.TaskExecchildThreadService;

public class TaskExecChildThread implements Runnable {

	private static final ZTEsoftLogManager LOGGER = ZTEsoftLogManager.getLogger(TaskExecChildThread.class);

	private Integer taskId;
	
	private DmTaskStageDao taskStageDao;

	private TaskExecchildThreadService taskExecchildThreadService;
	
	public TaskExecChildThread(Integer dmTaskId) {
		this.taskId = dmTaskId;
		taskStageDao = SpringApplicationContextHolder.getBean(DmTaskStageDao.class);
		taskExecchildThreadService = SpringApplicationContextHolder.getBean(TaskExecchildThreadService.class);
	}
	
	private DmTaskPO scheduleTask(List<DmTaskStagePO> stageLst) {
		return taskExecchildThreadService.runningScheduling(stageLst, taskId);
	}

	@Override
	public void run() {
//		DmTaskPO dmTaskPO = null;
		LOGGER.info(Thread.currentThread()+"|任务执行线程|TaskID={0}",taskId);
		List<DmTaskStagePO> stageLst = taskStageDao.selectStageAndStrategy(taskId);
		LOGGER.info(Thread.currentThread()+"|の策略数|:{0}",stageLst.size());
		if (stageLst.size() != 0) {
			scheduleTask(stageLst);
//			if (dmTaskPO !=null) {				
//				TaskNotify notify = DMSConstant.taskInstList.get(dmTaskPO.getDmTaskId());
//				notify.setStatus("00A");
//				DMSConstant.taskInstList.put(dmTaskPO.getDmTaskId(),notify);
//			}
			LOGGER.info(Thread.currentThread()+"|任务执行线程结束|TaskID={0}",taskId);
		}
	}
}
